package org.example;

public class Test1 {
    //leetcode 验证回文子串 https://leetcode.cn/problems/valid-palindrome/description/?envType=study-plan-v2&envId=top-interview-150
    public boolean isPalindrome(String s) {
        int n = s.length();
        int left = 0, right = n-1;
        s = s.toLowerCase();
        while (left < right) {
            while (left < right
                    && !Character.isAlphabetic(s.charAt(left))
                    && !Character.isDigit(s.charAt(left))) left++;
            while (left < right
                    && !Character.isAlphabetic(s.charAt(right))
                    && !Character.isDigit(s.charAt(right))) right--;
            if (s.charAt(left) != s.charAt(right)) return false;
            left++;
            right--;
        }
        return true;
    }
}
